package com.ldatum.crm.serviceImpl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.ldatum.crm.dao.TContactsDao;
import com.ldatum.crm.dao.TCustomerDao;
import com.ldatum.crm.daoImpl.TContactsDaoImpl;
import com.ldatum.crm.daoImpl.TCustomerDaoImpl;
import com.ldatum.crm.domain.TContacts;
import com.ldatum.crm.domain.TCustomer;
import com.ldatum.crm.service.TCustomerService;

public class TCustomerServiceImpl implements TCustomerService {
	
	TCustomerDao customerDao = new TCustomerDaoImpl();
	TContactsDao contactsDao = new TContactsDaoImpl();
	
	@Override
	public void add(TCustomer customer) throws Exception {
		customer.setBuildDate(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));
		customerDao.add(customer);
	}
	
	@Override
	public void save(TCustomer customer,TContacts contact) throws Exception {
		customer.setBuildDate(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));
		
		customerDao.save(customer,contact);
	}

	@Override
	public void delete(TCustomer customer, int id) throws Exception {
		customerDao.delete(customer,id);
	}

	@Override
	public void update(TCustomer customer, int id) throws Exception {
		customerDao.update(customer,id);
	}

	@Override
	public TCustomer findById(Class<TCustomer> clazz, int id) throws Exception {
		
		return customerDao.findById(clazz,id);
	}

	@Override
	public List<TCustomer> myCustomer(Class<TCustomer> clazz, String proprietor)
			throws Exception {
		List<TCustomer> list = customerDao.myCustomer(clazz,proprietor);
		return list;
	}

	@Override
	public String generateNo() throws Exception {
		String currentDate = new SimpleDateFormat("yyyyMMdd").format(new Date());
		return customerDao.generateNo(currentDate);
	}

	@Override
	public void deletes(TCustomer customer, String ids) throws Exception {
		ids = ids.substring(0,ids.length()-1);
		customerDao.deletes(customer, ids);
	}

	@Override
	public List<TCustomer> publicCustomer(Class<TCustomer> class1)
			throws Exception {
		List<TCustomer> list = customerDao.publicCustomer(class1);
		
		return list;
	}
	
	@Override
	public List<TCustomer> sharedCustomer(Class<TCustomer> class1)
			throws Exception {
		List<TCustomer> list = customerDao.sharedCustomer(class1);
		
		return list;
	}
}
